﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//using System.Net.Mail;

public partial class Templates_Contact_Default : Acms.AcmsControls.TemplatePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnSubmit.Click += new EventHandler(btnSubmit_Click);

    }

    void btnSubmit_Click(object sender, EventArgs e)
    {
      Validate();
      if (IsValid)
      {

        //create the mail message
            //MailMessage mail = new MailMessage();
          System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();

        //set the addresses
          mail.To.Add(new System.Net.Mail.MailAddress("izabela@clinicalappearance.co.uk", "Izabela"));
          mail.Bcc.Add("acmsemail@googlemail.com");
          //mail.To.Add(new System.Net.Mail.MailAddress("toma57@hotmail.com", "Moo Me"));

          mail.From = new System.Net.Mail.MailAddress(txtEmail.Text, txtName.Text);
            //mail.To.Add("you@yourcompany.com");
          
            //set the content
            mail.Subject = "Email from ClinicalApperance.Com";

            if (txtPhone.Text != "")
            {
                //var phone = string.Concat("Phone Number:", txtPhone.Text, "--");
                mail.Body=  string.Concat("Phone Number: ", txtPhone.Text, " -- ", txtQuestion.Text);
            }
            else
            {
                mail.Body = string.Concat("No Phone Number Provided. ", txtQuestion.Text);
            }

        //send the message

           // SmtpClient smtp = new System.Net.Mail.SmtpClient();
            //smtp.Send(mail);

            try
            {
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
                client.Send(mail);
                mail.Dispose();
                pnlMessageSent.Visible = true;
                pnlCreateMsg.Visible = false;
            }
            catch
            {
                pnlCreateMsg.Visible = false;
                pnlMessageError.Visible = true;

            }



          ////create the mail message
          //System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
          

          ////set the addresses
          //mail.To.Add(new System.Net.Mail.MailAddress("t.armfelt@gmail.com", "Thomas Armfelt"));
          //mail.To.Add(new System.Net.Mail.MailAddress("toma57@hotmail.com", "Moo Me"));
          


           //try
           // {
           //     System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
           //     client.Send(mail);
           //     mail.Dispose();
           // }
           // catch
           // {
           //     Failed = true;
           // }

           // this.To = string.Concat(mail.To[0].Address, ",", mail.To[0].DisplayName);
           // this.Sent = DateTime.Now;
           // this.Update();


        //  System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
        //    if (User != null)
        //    {
        //        mail.To.
        //        mail.To.Add(new System.Net.Mail.MailAddress(User.EmailAddress, User.DisplayName));
        //    }
        //    else
        //    {
        //        mail.To.Add(new System.Net.Mail.MailAddress(EmailAddress, Name));
        //    }
        //    AddAddresses(this.Cc, mail.CC);
        //    AddAddresses(this.Bcc, mail.Bcc);
        //    if (!string.IsNullOrEmpty(this.From))
        //        mail.From = GetAddress(From);
        //    if (!string.IsNullOrEmpty(this.ReplyTo))
        //        mail.ReplyTo = GetAddress(From);

        //    mail.Subject = this.Subject;
        //    mail.Body = this.Body;

        //    try
        //    {
        //        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
        //        client.Send(mail);
        //        mail.Dispose();
        //    }
        //    catch
        //    {
        //        Failed = true;
        //    }

        //    this.To = string.Concat(mail.To[0].Address, ",", mail.To[0].DisplayName);
        //    this.Sent = DateTime.Now;
        //    this.Update();
        //}
      }
    }
}
